"""CopyRight(C) From WangShiheng"""

# Author: WangShiheng
# Package: BaseLib.util.base.Pool.base
from typing import TypeVar

_T = TypeVar('_T')
_TO = TypeVar('_TO')


class BasePool(object):
    pool = []

    def Add(self, obj: _TO):
        if isinstance(obj, self.InObj):
            self.pool.append(obj)

    def Enum(self):
        for obj in self.pool:
            yield obj

    @property
    def num(self) -> int:
        return len(self.pool)

    def pop(self) -> object:
        return self.pool.pop(0)

    def __enter__(self: _T) -> _T:
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        ...

    def __init__(self, InObj=object):
        self.InObj = InObj

    def __iter__(self):
        return self.pool

    def __getitem__(self, item):
        return self.pool[item]
